﻿<UserControl x:Class="BookManager.Views.Controls.BookListItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ctrl="clr-namespace:BookManager.Views.Controls"
             xmlns:conv="clr-namespace:BookManager.Converters"
             mc:Ignorable="d" Height="126" Margin="3">
    <UserControl.Resources>
        <conv:RatingStarConverter x:Key="RatingStarConverter" />
    </UserControl.Resources>

    <Border Name="brdBookListItem" Width="{Binding DataContext.MySettings.BookListItemWidth, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
            VerticalAlignment="Top" HorizontalAlignment="Center"
            BorderBrush="Gray" BorderThickness="1" CornerRadius="3">
        <Grid Name="grdBookListItem" VerticalAlignment="Top" Margin="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.ToolTip>
                <TextBlock Text="{Binding Title, FallbackValue=TITLE}" />
            </Grid.ToolTip>

            <ctrl:BookCover x:Name="bkcovBookCoverItem" Grid.RowSpan="6" Margin="0" />

            <StackPanel Grid.Column="1" Margin="0,3,5,3" VerticalAlignment="Top" Orientation="Vertical">
                <TextBlock Name="txtbBookName" Text="{Binding Title, FallbackValue=TITLE}" FontWeight="Bold" />
                <TextBlock Name="txtbBinding" Text="{Binding Binding, FallbackValue=BINDING}" FontSize="9" />
                <StackPanel Name="stkRating" Orientation="Horizontal">
                    <StackPanel.ToolTip>
                        <TextBlock Text="{Binding PersonalRating, StringFormat='Rating : {0}'}" />
                    </StackPanel.ToolTip>
                    <ItemsControl Name="itmctrlRating" Height="54" HorizontalAlignment="Left" 
                                  ItemsSource="{Binding PersonalRating, Converter={StaticResource RatingStarConverter}}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Rows="2" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Margin="-1,-0.5,3,1.5" Padding="0,1,1,1" Width="25" 
                                        CornerRadius="0,10,0,8" BorderThickness="1" BorderBrush="{Binding BgCol, FallbackValue=Red}">
                                    <Image Name="imgRatingStar" Margin="0,0,0,0" Stretch="Fill" Source="/BookManager;component/Images/bookmgr_star.png" />
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <TextBlock Name="txtbRating" Margin="5,0" VerticalAlignment="Center"
                               FontSize="25" FontWeight="Bold" Text="{Binding PersonalRating, FallbackValue=0}" />
                </StackPanel>
                <TextBlock Name="txtbAuthor" Text="{Binding Author, FallbackValue=AUTHOR}">
                    <TextBlock.ToolTip>
                        <TextBlock Text="{Binding Author, StringFormat='Author : {0}'}" />
                    </TextBlock.ToolTip>
                </TextBlock>
                <TextBlock Name="txtbPublisher" Text="{Binding Publisher, FallbackValue=PUBLISHER}">
                    <TextBlock.ToolTip>
                        <TextBlock Text="{Binding Publisher, StringFormat='Publisher : {0}'}" />
                    </TextBlock.ToolTip>
                </TextBlock>
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
